package com.notes.algo.sx;

public class Solution3 {
    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        double beginCash = sc.nextDouble();
        int priceDay = sc.nextInt();
        String hisPriceStr = sc.next();
        String[] priceStrArr = hisPriceStr.split(",", -1);
        int[] hisPrices = new int[priceStrArr.length];
        for (int i = 0; i < priceStrArr.length; i++) {
            hisPrices[i] = Integer.valueOf(priceStrArr[i]);
        }

        int maxProfit = getMaxProfit(beginCash, hisPrices);
        System.out.println(maxProfit);

        int maxProfit2 = getMaxProfit2(beginCash, hisPrices);
        System.out.println(maxProfit2);
    }

    public static int getMaxProfit(double beginCash, int[] hisPrices) {
        int buyP = hisPrices[0];
        int sellP = 0;
        int profit = 0;
        int len = hisPrices.length;
        for (int i = 1; i < len; i++) {
            int curP = hisPrices[i];
            if (curP < buyP) {
                buyP = hisPrices[i];
            } else if (curP > buyP) {
                while (i + 1 < len && hisPrices[i + 1] > hisPrices[i]) {
                    i++;
                }

                sellP = hisPrices[i];
                double curProfit = (beginCash / buyP) * (sellP - buyP);
                profit += curProfit;
                if (i + 1 != len) {
                    buyP = hisPrices[i + 1];
                    beginCash += curProfit;
                    i = i + 1;
                }
            }
        }

        return profit;
    }

    public static int getMaxProfit2(double beginCash, int[] hisPrices) {
        int buyP = hisPrices[0];
        int profit = 0;
        int len = hisPrices.length;
        for (int i = 1; i < len; i++) {
            int curP = hisPrices[i];
            if (curP < buyP) {
                buyP = hisPrices[i];
            } else if (curP > buyP) {
                double curProfile = (curP - buyP) * (beginCash / buyP);
                profit += curProfile;
                beginCash += curProfile;
                buyP = hisPrices[i];
            }
        }

        return profit;
    }
}
